package it.polito.let.http;

import java.util.*;

public class HTTPConstants {
	// porta su cui il server è in ascolto
	static final int HTTP_PORT = 2010;
	// protocolli
	static final int HTTP = 0;
	static final int FTP = 1;
	static final int TELNET = 2;
	static final int NNTP = 3;
	// comandi HTTP
	public static final String TYPE_HEAD = "HEAD";
	public static final String TYPE_GET = "GET";
	public static final String TYPE_POST = "POST";
	static final int GET = 0;
	static final int POST = 1;
	static final int IF_NOT_MODIFIED = 2;
	// risposte HTTP
	static final int FILE_NOT_FOUND = 0;
	static final int FILE_NOT_MODIFIED = 1;
	static final int REQ_OK = 2;
	static final String CRLF = "\r\n";
	// dimensione del buffer
	static final int PACCHETTO = 100000;
	// numero risposte figli massimo
	static final int MAX_REQ = 5;

	final static HTTPMethod[] REQUESTS_SUPPORTED = { HTTPMethod.HEAD, HTTPMethod.GET, HTTPMethod.POST }; 
	final static String[] VERSIONS_SUPPORTED = { "1.0", "1.1" };
	final static String[] PARAMETER_HEADERS = { "Content-Disposition", "Content-Type" }; 


	@SuppressWarnings("serial")
	private static final Map<String, String> MAP_TYPE = Collections
	.unmodifiableMap(new HashMap<String, String>() {
		{
			put("jhp", "text/html");
			put("afl", "video/animaflex");
			put("ai", "application/postscript");
			put("aif", "audio/aiff");
			put("aifc", "audio/x-aiff");
			put("aiff", "audio/x-aiff");
			put("aim", "application/x-aim");
			put("aip", "text/x-audiosoft-intra");
			put(".ani", "application/x-navi-animation");
			put("aos",
			"application/x-nokia-9000-communicator-add-on-software");
			put("aps", "application/mime");
			put("arc", "application/octet-stream");
			put("arj", "application/arj");
			put("art", "image/x-jg");
			put("asf", "video/x-ms-asf");
			put("asm", "text/x-asm");
			put("asp", "text/asp");
			put("asx", "video/x-ms-asf");
			put("au", "audio/basic");
			put("avi", "application/x-troff-msvideo");
			put("avs", "video/avs-video");
			put("bcpio", "application/x-bcpio");
			put("bin", "application/x-binary");
			put("bm", "image/bmp");
			put("bmp", "image/bmp");
			put("boo", "application/book");
			put("book", "application/book");
			put("boz", "application/x-bzip2");
			put("bsh", "application/x-bsh");
			put("bz", "application/x-bzip");
			put("bz2", "application/x-bzip2");
			put("c", "text/plain");
			put("c++", "text/plain");
			put("cat", "application/vnd.ms-pki.seccat");
			put("cc", "text/plain");
			put("ccad", "application/clariscad");
			put("cco", "application/x-cocoa");
			put("cdf", "application/cdf");
			put("cer", "application/pkix-cert");
			put("cha", "application/x-chat");
			put("chat", "application/x-chat");
			put("class", "application/java");
			put("com", "text/plain");
			put("conf", "text/plain");
			put("cpio", "application/x-cpio");
			put("cpp", "text/x-c");
			put("cpt", "application/x-cpt");
			put("crl", "application/pkcs-crl");
			put("crt", "application/pkix-cert");
			put("csh", "application/x-csh");
			put("css", "text/css");
			put("cxx", "text/plain");
			put("dcr", "application/x-director");
			put("deepv", "application/x-deepv");
			put("def", "text/plain");
			put("der", "application/x-x509-ca-cert");
			put("dif", "video/x-dv");
			put("dir", "application/x-director");
			put("dl", "video/dl");
			put("doc", "application/msword");
			put("dot", "application/msword");
			put("dp", "application/commonground");
			put("drw", "application/drafting");
			put("dump", "application/octet-stream");
			put("dv", "video/x-dv");
			put("dvi", "application/x-dvi");
			put("dwf", "model/vnddwf");
			put("dwg", "image/x-dwg");
			put("dxf", "image/x-dwg");
			put("dxr", "application/x-director");
			put("el", "text/x-scriptelisp");
			put("elc", "application/x-bytecodeelisp (compiled elisp)");
			put("env", "application/x-envoy");
			put("eps", "application/postscript");
			put("es", "application/x-esrehber");
			put("etx", "text/x-setext");
			put("evy", "application/envoy");
			put("exe", "application/octet-stream");
			put("f", "text/plain");
			put("fdf", "application/vndfdf");
			put("fif", "image/fif");
			put("fli", "video/fli");
			put("flo", "image/florian");
			put("flx", "text/vndfmiflexstor");
			put("fmf", "video/x-atomic3d-feature");
			put("for", "text/plain");
			put("fpx", "image/vndfpx");
			put("frl", "application/freeloader");
			put("funk", "audio/make");
			put("gif", "image/gif");
			put("gl", "video/gl");
			put("gsd", "audio/x-gsm");
			put("gsm", "audio/x-gsm");
			put("gsp", "application/x-gsp");
			put("gss", "application/x-gss");
			put("gtar", "application/x-gtar");
			put("gz", "application/x-gzip");
			put("gzip", "application/x-gzip");
			put("h", "text/plain");
			put("hdf", "application/x-hdf");
			put("help", "application/x-helpfile");
			put("hgl", "application/vndhp-hpgl");
			put("hh", "text/plain");
			put("hlb", "text/x-script");
			put("hlp", "application/hlp");
			put("hpg", "application/vndhp-hpgl");
			put("hpgl", "application/vndhp-hpgl");
			put("hqx", "application/binhex");
			put("hta", "application/hta");
			put("htc", "text/x-component");
			put("htm", "text/html");
			put("html", "text/html");
			put("htmls", "text/html");
			put("htt", "text/webviewhtml");
			put("htx", "text/html");
			put("ice", "x-conference/x-cooltalk");
			put("ico", "image/x-icon");
			put("idc", "text/plain");
			put("ief", "image/ief");
			put("iefs", "image/ief");
			put("iges", "application/iges");
			put("igs", "model/iges");
			put("ima", "application/x-ima");
			put("imap", "application/x-httpd-imap");
			put("inf", "application/inf");
			put("ins", "application/x-internett-signup");
			put("ip", "application/x-ip2");
			put("isu", "video/x-isvideo");
			put("it", "audio/it");
			put("iv", "application/x-inventor");
			put("ivr", "i-world/i-vrml");
			put("ivy", "application/x-livescreen");
			put("jam", "audio/x-jam");
			put("jav", "text/plain");
			put("java", "text/plain");
			put("jcm", "application/x-java-commerce");
			put("jfif", "image/jpeg");
			put("jfif-tbnl", "image/jpeg");
			put("jpe", "image/jpeg");
			put("jpeg", "image/jpeg");
			put("jpg", "image/jpeg");
			put("jps", "image/x-jps");
			put("js", "application/x-javascript");
			put("jut", "image/jutvision");
			put("kar", "audio/midi");
			put("ksh", "text/x-scriptksh");
			put("la", "audio/nspaudio");
			put("lam", "audio/x-liveaudio");
			put("latex", "application/x-latex");
			put("lha", "application/lha");
			put("lhx", "application/octet-stream");
			put("list", "text/plain");
			put("lma", "audio/nspaudio");
			put("log", "text/plain");
			put("lsp", "application/x-lisp");
			put("lst", "text/plain");
			put("lsx", "text/x-la-asf");
			put("ltx", "application/x-latex");
			put("lzh", "application/x-lzh");
			put("lzx", "application/lzx");
			put("m", "text/plain");
			put("m1v", "video/mpeg");
			put("m2a", "audio/mpeg");
			put("m2v", "video/mpeg");
			put("m3u", "audio/x-mpequrl");
			put("man", "application/x-troff-man");
			put("map", "application/x-navimap");
			put("mar", "text/plain");
			put("mbd", "application/mbedlet");
			put("mc$", "application/x-magic-cap-package-1.0");
			put("mcd", "application/mcad");
			put("mcf", "text/mcf");
			put("mcp", "application/netmc");
			put("me", "application/x-troff-me");
			put("mht", "message/rfc822");
			put("mhtml", "message/rfc822");
			put("mid", "audio/midi");
			put("midi", "audio/midi");
			put("mif", "application/x-frame");
			put("mime", "message/rfc822");
			put("mjf", "audio/x-vnd.audioexplosion.mjuicemediafile");
			put("mjpg", "video/x-motion-jpeg");
			put("mm", "application/x-meme");
			put("mme", "application/base64");
			put("mod", "audio/mod");
			put("moov", "video/quicktime");
			put("mov", "video/quicktime");
			put("movie", "video/x-sgi-movie");
			put("mp2", "audio/mpeg");
			put("mp3", "audio/mpeg3");
			put("mpa", "audio/mpeg");
			put("mpc", "application/x-project");
			put("mpe", "video/mpeg");
			put("mpeg", "video/mpeg");
			put("mpg", "video/mpeg");
			put("mpga", "audio/mpeg");
			put("mpp", "application/vndms-project");
			put("mpt", "application/x-project");
			put("mpv", "application/x-project");
			put("mpx", "application/x-project");
			put("mrc", "application/marc");
			put("ms", "application/x-troff-ms");
			put("my", "audio/make");
			put("mzz", "application/x-vnd.audioexplosion.mzz");
			put("nap", "image/naplps");
			put("naplps", "image/naplps");
			put("nc", "application/x-netcdf");
			put("ncm", "application/vnd.nokia.configuration-message");
			put("nif", "image/x-niff");
			put("niff", "image/x-niff");
			put("nix", "application/x-mix-transfer");
			put("nsc", "application/x-conference");
			put("nvd", "application/x-navidoc");
			put("o", "application/octet-stream");
			put("oda", "application/oda");
			put("omc", "application/x-omc");
			put("omcd", "application/x-omcdatamaker");
			put("omcr", "application/x-omcregerator");
			put("p", "text/x-pascal");
			put("part", "application/pro_eng");
			put("pas", "text/pascal");
			put("pbm", "image/x-portable-bitmap");
			put("pct", "image/x-pict");
			put("pcx", "image/x-pcx");
			put("pdb", "chemical/x-pdb");
			put("pdf", "application/pdf");
			put("pfunk", "audio/make");
			put("pgm", "image/x-portable-graymap");
			put("pic", "image/pict");
			put("pict", "image/pict");
			put("pkg", "application/x-newton-compatible-pkg");
			put("pko", "application/vnd.ms-pki.pko");
			put("pl", "text/plain");
			put("plx", "application/x-pixclscript");
			put("pm", "text/x-script.perl-module");
			put("pm4", "application/x-pagemaker");
			put("pm5", "application/x-pagemaker");
			put("png", "image/png");
			put("pnm", "image/x-portable-anymap");
			put("pot", "application/mspowerpoint");
			put("pov", "model/x-pov");
			put("ppa", "application/vnd.ms-powerpoint");
			put("ppm", "image/x-portable-pixmap");
			put("pps", "application/vnd.ms-powerpoint");
			put("ppt", "application/powerpoint");
			put("ppz", "application/mspowerpoint");
			put("pre", "application/x-freelance");
			put("prt", "application/pro_eng");
			put("ps", "application/postscript");
			put("psd", "application/octet-stream");
			put("pvu", "paleovu/x-pv");
			put("pwz", "application/vnd.ms-powerpoint");
			put("py", "text/x-script.phyton");
			put("pyc", "applicaiton/x-bytecode.python");
			put("qcp", "audio/vnd.qcelp");
			put("qd3", "x-world/x-3dmf");
			put("qd3d", "x-world/x-3dmf");
			put("qif", "image/x-quicktime");
			put("qt", "video/quicktime");
			put("qtc", "video/x-qtc");
			put("qti", "image/x-quicktime");
			put("qtif", "image/x-quicktime");
			put("ra", "audio/x-pn-realaudio");
			put("ram", "audio/x-pn-realaudio");
			put("ras", "image/cmu-raster");
			put("rast", "image/cmu-raster");
			put("rexx", "text/x-script.rexx");
			put("rf", "image/vnd.rn-realflash");
			put("rgb", "image/x-rgb");
			put("rm", "audio/x-pn-realaudio");
			put("rmi", "audio/mid");
			put("rmm", "audio/x-pn-realaudio");
			put("rmp", "audio/x-pn-realaudio");
			put("rmp", "audio/x-pn-realaudio-plugin");
			put("rng", "application/ringing-tones");
			put("rnx", "application/vnd.rn-realplayer");
			put("roff", "application/x-troff");
			put("rp", "image/vnd.rn-realpix");
			put("rpm", "audio/x-pn-realaudio-plugin");
			put("rt", "text/richtext");
			put("rtf", "application/rtf");
			put("rv", "video/vnd.rn-realvideo");
			put("s", "text/x-asm");
			put("s3m", "audio/s3m");
			put("saveme", "application/octet-stream");
			put("sbk", "application/x-tbook");
			put("scm", "text/x-script.guile");
			put("sdml", "text/plain");
			put("sdp", "application/sdp");
			put("sdr", "application/sounder");
			put("sea", "application/sea");
			put("set", "application/set");
			put("sgm", "text/sgml");
			put("sgml", "text/sgml");
			put("sh", "application/x-bsh");
			put("shar", "application/x-shar");
			put("shtml", "text/html");
			put("sid", "audio/x-psid");
			put("sit", "application/x-sit");
			put("skd", "application/x-koan");
			put("skm", "application/x-koan");
			put("skp", "application/x-koan");
			put("skt", "application/x-koan");
			put("sl", "application/x-seelogo");
			put("smi", "application/smil");
			put("smil", "application/smil");
			put("snd", "audio/basic");
			put("sol", "application/solids");
			put("spc", "text/x-speech");
			put("spl", "application/futuresplash");
			put("spr", "application/x-sprite");
			put("sprite", "application/x-sprite");
			put("src", "application/x-wais-source");
			put("ssi", "text/x-server-parsed-html");
			put("ssm", "application/streamingmedia");
			put(".sst", "application/vnd.ms-pki.certstore");
			put("step", "application/step");
			put("stl", "application/sla");
			put("stp", "application/step");
			put("sv4cpio", "application/x-sv4cpio");
			put("sv4crc", "application/x-sv4crc");
			put("svf", "image/x-dwg");
			put("svr", "application/x-world");
			put("swf", "application/x-shockwave-flash");
			put("t", "application/x-troff");
			put("talk", "text/x-speech");
			put("tar", "application/x-tar");
			put("tbk", "application/toolbook");
			put("tcl", "text/x-script.tcl");
			put("tcsh", "text/x-script.tcsh");
			put("tex", "application/x-tex");
			put("texi", "application/x-texinfo");
			put("texinfo", "application/x-texinfo");
			put("text", "text/plain");
			put("tgz", "application/gnutar");
			put("tif", "image/tiff");
			put("tr", "application/x-troff");
			put("tsi", "audio/tsp-audio");
			put("tsp", "audio/tsplayer");
			put("tsv", "text/tab-separated-values");
			put("turbot", "image/florian");
			put("txt", "text/plain");
			put("uil", "text/x-uil");
			put("uni", "text/uri-list");
			put("unis", "text/uri-list");
			put("unv", "application/i-deas");
			put("uri", "text/uri-list");
			put("uris", "text/uri-list");
			put("ustar", "application/x-ustar");
			put("uu", "text/x-uuencode");
			put("uue", "text/x-uuencode");
			put("vcd", "application/x-cdlink");
			put("vcs", "text/x-vcalendar");
			put("vda", "application/vda");
			put("vdo", "video/vdo");
			put("vew", "application/groupwise");
			put("viv", "video/vivo");
			put("vivo", "video/vivo");
			put("vmd", "application/vocaltec-media-desc");
			put("vmf", "application/vocaltec-media-file");
			put("voc", "audio/voc");
			put("vos", "video/vosaic");
			put("vox", "audio/voxware");
			put("vqe", "audio/x-twinvq-plugin");
			put("vqf", "audio/x-twinvq");
			put("vql", "audio/x-twinvq-plugin");
			put("vrml", "x-world/x-vrml");
			put("vrt", "x-world/x-vrt");
			put("vsd", "application/x-visio");
			put("vst", "application/x-visio");
			put("vsw", "application/x-visio");
			put("wav", "audio/wav");
			put("wb1", "application/x-qpro");
			put("wbmp", "image/vnd.wapwbmp");
			put("web", "application/vnd.xara");
			put("wiz", "application/msword");
			put("wk1", "application/x-123");
			put("wmf", "windows/metafile");
			put("wml", "text/vnd.wap.wml");
			put("wmlc", "application/vnd.wap.wmlc");
			put("wmls", "text/vnd.wap.wmlscript");
			put("wmlsc", "application/vnd.wap.wmlscriptc");
			put("word", "application/msword");
			put("wp", "application/wordperfect");
			put("wp5", "application/wordperfect");
			put("wp6", "application/wordperfect");
			put("wpd", "application/wordperfect");
			put("wq1", "application/x-lotus");
			put("wri", "application/mswrite");
			put("wrz", "model/vrml");
			put("wrz", "x-world/x-vrml");
			put("wsc", "text/scriplet");
			put("wsrc", "application/x-wais-source");
			put("wtk", "application/x-wintalk");
			put("xbm", "image/x-xbitmap");
			put("xdr", "video/x-amt-demorun");
			put("xgz", "xgl/drawing");
			put("xif", "image/vnd.xiff");
			put("xl", "application/excel");
			put("xla", "application/excel");
			put("xlb", "application/excel");
			put("xlc", "application/excel");
			put("xld", "application/excel");
			put("xlk", "application/excel");
			put("xll", "application/excel");
			put("xlm", "application/excel");
			put("xls", "application/excel");
			put("xlt", "application/excel");
			put("xlv", "application/excel");
			put("xlw", "application/excel");
			put("xlw", "application/x-excel");
			put("xm", "audio/xm");
			put("xml", "text/xml");
			put("xmz", "xgl/movie");
			put("xpix", "application/x-vnd.ls-xpix");
			put("xpm", "image/xpm");
			put("x-png", "image/png");
			put("xsr", "video/x-amt-showrun");
			put("xwd", "image/x-xwd");
			put("xyz", "chemical/x-pdb");
			put("z", "application/x-compress");
			put("zip", "application/x-compressed");
			put("zip", "application/zip");
			put("zoo", "application/octet-stream");
			put("zsh", "text/x-script.zsh");

		}
	});

	public static String convertExensionType(String ext) throws HTTPError {
		String s = MAP_TYPE.get(ext);
		if (s != null)
			return s;
		return "text/plain";
	}

}